<template>
  <div class="store">
    <!-- <div @click="$pt.navigateTo({url:'/pages/home/leader-apply/main'})">申请店主页</div> -->
    <user-login v-if="hasLogin" @updateAuth="updateAuth"></user-login>
    <div class="store-center" v-if="getCustomerId && getPhone">
      <div class="store-nav" :style="{height: spaceBarHeight + 'px'}">
        <div v-if="loginType === 2" class="switch-auth" :style="{paddingTop: menuButtonInfo['top'] + 'px', height: menuButtonInfo['height'] + 'px'}" @click="switchAuth">
          <van-icon name="exchange" />
          <span>切换账号</span>
        </div>
        <div class="store-title" :style="{paddingTop: menuButtonInfo['top'] + 'px', height: menuButtonInfo['height'] + 'px'}">店主中心</div>
      </div>
      <div class="pad-l-12 pad-r-12" :style="{paddingTop: spaceBarHeight + 'px'}">
        <div class="store-info flex flex-between">
          <div class="aling-l flex-item">
            <img class="store-logo" v-if="storeLogo" :src="storeLogo" alt="">
            <div class="mar-l-8">
              <div class="store-name font-w line-1">{{storeName}}</div>
              <div class="store-phone">{{storePhone}}</div>
            </div>
          </div>
          <div class="switch-info" @click="$pt.navigateToMiniProgram({appId: getAppInfo.shopAppId || ''})">
            <img class="width-15 height-15" v-if="fileSpace" :src="fileSpace + '/images/store-icon-switch-1.png'" alt="">
            <div class="mar-l-3">切换为买家</div>
          </div>
        </div>
        <div class="flex flex-between font-white font-16 mar-t-10" v-if="!memberStore.isHomeDelivery && !memberStore.isStoreExtraction">
          <div class="text-align-c" @click="$pt.switchTab({url: '/pages/order/main'})">
            <div>{{memberStat.orderCommission}}</div>
            <div class="v-align-c font-12">今日预计收入<van-icon name="arrow" /></div>
          </div>
          <div class="text-align-c" @click="$pt.switchTab({url: '/pages/order/main'})">
            <div>{{memberStat.orderNum}}</div>
            <div class="v-align-c font-12">今日成交件数<van-icon name="arrow" /></div>
          </div>
          <div class="text-align-c" @click="$pt.navigateTo({url:'/pages/home/visitor/main'})">
            <div>{{memberStat.dailyAccess}}</div>
            <div class="v-align-c font-12">今日访客数<van-icon name="arrow" /></div>
          </div>
        </div>
        <!-- 搜索 -->
        <div class="search-box mar-b-16">
          <input type="text" class="font-12 pad-l-15" v-model="searchvalue" placeholder="输入提货码/顾客手机号/订单编号">
          <span @click="goSearchPage">
            <van-icon name="search" class="font-20"/>
          </span>
        </div>
        <!-- 店主视角 -->
        <template v-if="getVeekrayStatus === 1 && getCommanderStatus !== 1">
          <div class="increment-box v-align-c mar-b-15" v-if="entityData.enterpriseId && entityData.liveAuthority && getShowBuyCard">
            <div class="flex-item pos-rel width-max" v-if="barObj.leftList.length > 0" @click="$pt.navigateTo({ url: barObj.leftList[0].linkTo})">
              <img v-if="fileSpace" :src="barObj.leftList[0].src" alt="" class="width-max" :class="barObj.leftList[0].className">
              <div class="text-layer" :style="barObj.leftList[0].titleLeft">
                <div class="font-w" :class="barObj.leftList[0].titleFont">{{barObj.leftList[0].lineOne}}</div>
                <div class="font-10 font-81">{{barObj.leftList[0].lineTwo}}</div>
                <div class="font-10 font-81 mar-t--2" v-if="barObj.leftList[0].lineThree">{{barObj.leftList[0].lineThree}}</div>
              </div>
            </div>
            <div class="flex-item align-c mar-l-5" v-if="barObj.rightList.length > 0">
              <div class="pos-rel width-max" v-for="(item, index) in barObj.rightList" :key="index" :class="{'mar-t-6': index === 1 && barObj.rightList.length > 1}" @click="$pt.navigateTo({ url: item.linkTo})">
                <img v-if="fileSpace" :src="item.src" alt="" class="width-max" :class="item.className">
                <div class="text-layer" :style="item.titleLeft">
                  <div class="font-w" :class="item.titleFont">{{item.lineOne}}</div>
                  <div class="font-10 font-81">{{item.lineTwo}}</div>
                  <div class="font-10 font-81 mar-t--2" v-if="item.lineThree">{{item.lineThree}}</div>
                </div>
              </div>
            </div>
          </div>
          <div class="pancel-bar none-radius mar-b-10">
            <h3 class="pancel-title">店铺工具</h3>
            <ul class="flex v-align-c pad-t-19 pad-b-17 shop-tools">
              <li class="self-flex-item" @click="$pt.navigateTo({url:'/pages/home/customer-manage/main'})">
                <img v-if="fileSpace" :src="fileSpace + '/images/icon-customer-4.png'" class="width-23 height-23" alt="">
                <label>顾客管理</label>
              </li>
              <li v-if="entityData.selfGoodsAuthority === 1" class="self-flex-item" @click="$pt.navigateTo({url:'/pages/home/editView/main'})">
                <img v-if="fileSpace" :src="fileSpace + '/images/icon-shop-4.png'" class="width-23 height-23" alt="">
                <label>店铺管理</label>
              </li>
              <li class="self-flex-item" @click="$pt.navigateTo({url:'/pages/home/customer-share/main'})">
                <img v-if="fileSpace" :src="fileSpace + '/images/icon-cshare-4.png'" class="width-23 height-23" alt="">
                <label>{{getAppInfo.customerShareAlias || '顾客分销'}}</label>
              </li>
              <li v-if="!pickUpFlag && entityData.selfGoodsAuthority === 1" class="self-flex-item" @click="$pt.navigateTo({url:'/pages/home/application-market/main'})">
                <img v-if="fileSpace" :src="fileSpace + '/images/label-list-6.png'" class="width-23 height-20" alt="">
                <label>应用市场</label>
              </li>
              <li v-if="pickUpFlag && entityData.selfGoodsAuthority === 1" class="flex-item" @click="$pt.navigateTo({url:'/pages/home/cancellation-desk/main'})">
                <img v-if="fileSpace" :src="fileSpace + '/images/icon-pickup-4.png'" class="width-23 height-23" alt="">
                <label>核销台</label>
              </li>
              <li class="self-flex-item mar-t-30 new-item" @click="$pt.navigateTo({url:'/pages/home/anchor-income/main'})" v-if="anchorAuth === 1">
                <img v-if="fileSpace" :src="fileSpace + '/images/anchor-income.png'" class="width-22 height-21" alt="">
                <label>主播收入</label>
                <span class="new-tag">New</span>
              </li>
            </ul>
          </div>
          <!-- 其他工具 -->
          <div class="pancel-bar none-radius mar-b-10">
            <h3 class="pancel-title">其他工具</h3>
            <ul class="flex v-align-c pad-b-17" style="flex-wrap:wrap">
              <li @click="$pt.navigateTo({url:'/pages/home/weekly/main'})" style="width:25%;" class="pad-t-19">
                <img v-if="fileSpace" :src="fileSpace + '/images/label-list-1.png'" class="icon width-18 height-22" alt="">
                <label>获取周报</label>
              </li>
              <li @click="$pt.navigateTo({url:'/pages/home/poster/main'})" v-if="enterpriseId" style="width:25%;" class="pad-t-19">
                <img v-if="fileSpace" :src="fileSpace + '/images/label-list-2.png'" mode=" widthFix" class="icon width-19 height-19" alt="">
                <label>每日海报</label>
              </li>
              <!-- 联系客服 根据企业客服增值功能来显示和隐藏 -->
              <li class="pos-rel pad-t-19" style="width:25%;" v-if="enterpriseCustomerServiceAuthority">
                <button open-type="contact" class="contactBtn hidden-submit button-icon" :session-from="'7moor|'+ memberInfo.nickname + '|' + memberInfo.avatar +'|'+ customField"></button>
                <img v-if="fileSpace" :src="fileSpace + '/images/label-list-4.png'" class="icon width-21 height-21" alt="">
                <label>联系客服</label>
              </li>
              <!-- 原流程中需要根据条件v-if="!pickUpFlag"决定是否显示设置按钮  -->
              <li @click="$pt.navigateTo({url:'/pages/home/setting-view/main?from=1'})" style="width:25%;" class="pad-t-19">
                <img v-if="fileSpace" :src="fileSpace + '/images/label-list-3.png'" class="icon width-21 height-20" alt="">
                <label>设置</label>
              </li>
              <li style="width:25%;" class="pad-t-19" v-if="shopCustomerServiceAuthority" @click="serviceTo">
                <div style="position:relative">
                  <img v-if="fileSpace" :src="fileSpace + '/images/news-icon.png'" class="icon width-28 height-28" alt="">
                  <span :class="unread['buyerUnread'] > 99 ?'news-tag-style1' : 'news-tag-style2'" v-if="unread['buyerUnread'] > 0">{{unread['buyerUnread']}}</span>
                </div>
                <label>消息</label>
              </li>
              <li class="flex-item" v-if="!enterpriseId">&nbsp;</li>
            </ul>
          </div>
          <!-- 前往任务宝 -->
          <div v-if="getShowBuyCard" :class="statusIs ? 'light-bg mar-l--15 mar-r--15 pad-l-15 pad-r-15' : ''">
            <div v-if="getShowBuyCard && taskPosterAuth" class="banner" @click="$pt.navigateToMiniProgram({appId: 'wxf90184050e49c24f'})">
              <img v-if="fileSpace" mode="widthFix" class="width-346 height-95 border-radius-5" :src="fileSpace + '/images/get_task_3.png'" />
            </div>
            <div v-if="showWatermarkAuthority">
              <div v-if="!enterpriseCopy.watermarkAuthority" class="copy-right text-align-c pad-10 font-12">©{{ getAppInfo.appName }} 版本号：{{ getAppInfo.appVersion }}</div>
              <div v-else class="copy-right-logo text-align-c">
                <img v-if="fileSpace" mode="widthFix" class="width-44 height-17" :src="fileSpace + '/images/copy-right-logo.png'" />
                <p class="font-10">众项提供技术支持</p>
              </div>
            </div>
          </div>
        </template>
        <!-- 团长视角 -->
        <div class="pancel-bar none-radius pad-t-20" v-if="getCommanderStatus === 1">
          <div class="cancellation-tool flex flex-between">
            <div class="flex-item align-c tool-line"
              v-if="groupBuyAuthority === 1 && memberStore.isCommunityGroupExtraction"
              @click="$pt.navigateTo({ url: '/pages/home/delivery-list/main?deliveryStatus=20' })"
            >
              <div class="pos-rel">
                <img class="tool-icon" v-if="fileSpace" :src="fileSpace + '/images/store-icon-send.png'" alt="">
                <div class="cancellation-dot" v-if="statOrderTotal.deliveryNum">{{statOrderTotal.deliveryNum}}</div>
              </div>
              <div class="text-align-c mar-t-10 font-13">配送签收</div>
            </div>
            <div class="flex-item align-c tool-line" v-if="memberStore.isHomeDelivery === 1 || memberStore.isStoreExtraction === 1" @click="goOrderList(1)">
              <div class="pos-rel">
                <img class="tool-icon" v-if="fileSpace" :src="fileSpace + '/images/store-icon-selfPU.png'" alt="">
                <div class="cancellation-dot" v-if="statOrderTotal.homeDeliveryOrderNum">{{statOrderTotal.homeDeliveryOrderNum}}</div>
              </div>
              <div class="text-align-c mar-t-10 font-13">门店自提</div>
            </div>
            <div class="flex-item align-c" @click="getScanning">
              <img class="tool-icon" v-if="fileSpace" :src="fileSpace + '/images/store-icon-scanSale.png'" alt="">
              <div class="text-align-c mar-t-10 font-13">扫码核销</div>
            </div>
          </div>
          <div class="order-tip">
            <div class="v-align-c" @click="goOrderList(2)">
              <img class="width-21 height-21" v-if="fileSpace" :src="fileSpace + '/images/store-icon-1.png'" alt="">
              <div class="mar-l-4 font-12">待提货(<span style="color: #ED4836;">{{statOrderTotal.groupBuyDeliveryOrderNum + statOrderTotal.homeDeliveryOrderNum}}</span>)</div>
            </div>
            <div class="v-align-c"
              v-if="groupBuyAuthority === 1 && memberStore.isCommunityGroupExtraction"
              @click="goOrderList(3)"
            >
              <img class="width-21 height-21" v-if="fileSpace" :src="fileSpace + '/images/store-icon-2.png'" alt="">
              <div class="mar-l-4 font-12">待配送(<span style="color: #ED4836;">{{statOrderTotal.groupBuyPaidOrderNum}}</span>)</div>
            </div>
            <div class="v-align-c" @click="goOrderList(4)">
              <img class="width-21 height-21" v-if="fileSpace" :src="fileSpace + '/images/store-icon-3.png'" alt="">
              <div class="mar-l-4 font-12">全部订单</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import UserLogin from '@/components/UserLogin'
import { getMemberInfo, statOrder } from '@/api/home'
import { getEntityByMemberId, getSysAppMarketByMemberId, getEnterpriseByMemberId, statMemberCommission } from '@/api/personal'
import { getAppInfo, getAuthority, listEnterpriseMessageConfig, parseShortCode } from '@/api/common'
import { checkPayMethod } from '@/api/pay'
import {
  setVeekrayStatus,
  setAppInfo,
  setEnterpriseId,
  setNickName,
  setCommanderStatus,
  setPhone,
  setPayMethod,
  setCustomerId,
  setMemberId,
  setCommunityGroup } from '@/utils/auth'
import { appColor } from '@/api/appColor'
export default {
  components: {
    UserLogin
  },
  data() {
    return {
      storeLogo: '', // 门店照片/团长头像/店主头像
      storeName: '', // 门店名称/团长名称/店主名称
      storePhone: '', // 门店电话/团长电话/店主电话
      groupBuyAuthority: 0, // 社区团购的增值功能是否开启
      hasLogin: false,
      spaceBarHeight: 0,
      menuButtonInfo: {},
      shopCustomerServiceAuthority: 1, // 小B客服增值功能 0关闭 1开启
      enterpriseCustomerServiceAuthority: 1, // 企业客服增值功能 0关闭 1开启
      shopSelectionAuthority: 0, // 小B选品增值功能 0关闭 1开启
      taskPosterAuth: false,
      entityData: {},
      searchvalue: '',
      barObj: {
        leftList: [],
        rightList: []
      },
      unread: {
        sellerUnread: 0, // 买家收到 卖家的消息(未读消息数)
        buyerUnread: 0 // 卖家收到 买家的消息(未读数)
      },
      getAppInfo: {},
      pickUpFlag: false,
      enterpriseId: '',
      memberInfo: {
        memberStore: {}
      },
      memberStore: {},
      shareType: false,
      enterpriseCopy: {},
      showWatermarkAuthority: false,
      leaderApply: false,
      openId: '',
      statOrderTotal: {
        deliveryNum: 0,
        groupBuyDeliveryOrderNum: 0,
        groupBuyPaidOrderNum: 0,
        homeDeliveryOrderNum: 0
      },
      memberStat: {
        orderCommission: '0.00',
        orderNum: 0,
        dailyAccess: 0
      }, // 数据统计
      // loginType: 0, // 设置登录类型 1： 社群/团长身份登录 2：门店身份登录
      messageIdsArr: [
        {
          dataArr: ['1501', '1502'], // 小B客服消息订阅
          ids: []
        },
        {
          dataArr: ['1202', '1203', '1204'], // 退货/退款 消息订阅
          ids: []
        },
        {
          // dataArr: ['1101', '1105', '1103', '1104'], // 待发货、取消订单、已收货、待收货 消息订阅
          dataArr: ['1101', '1103', '1104'], // 待发货、取消订单、已收货、待收货 消息订阅，// 订阅类型最多接受3个
          ids: []
        },
        {
          dataArr: ['1401', '1402'], // 退货/退款 消息订阅
          ids: []
        }
      ]
    }
  },
  computed: {
    loginType() {
      return !this.hasLogin ? this.$pt.getStorageSync('loginType') : 0
    }
  },
  onLoad() {
    // 初始化data
    Object.assign(this.$data, this.$options.data())
    // 获取胶囊按钮信息
    let menuButtonInfo = wx.getMenuButtonBoundingClientRect()
    this.menuButtonInfo = menuButtonInfo
    // 设备信息
    let devInfo = this.$pt.getSystemInfoSync()
    // 整个导航栏高度
    this.spaceBarHeight = devInfo['statusBarHeight'] + menuButtonInfo['height'] + (menuButtonInfo['top'] - devInfo['statusBarHeight']) * 2
  },
  mounted() {
    this.initHome()
  },
  async onShow() {
    await this.getAppEls()
    if (this.getCustomerId && this.getPhone) {
      this.$pt.checkSession({
        success: async res => {
          this.loginType = this.$pt.getStorageSync('loginType')
          await this.getMemberInfo()
          this.authority()
        },
        fail: () => {
          this.hasLogin = true
          this.$pt.hideTabBar({
            animation: false
          })
        }
      })
    } else {
      let path = this.getCurrentPage().query.path
      path === 'leader-apply' && this.$pt.setStorageSync('leader-apply', true)
      this.hasLogin = true
      this.$pt.hideTabBar({
        animation: false
      })
    }
  },
  methods: {
    async initHome() {
      if (this.getCustomerId && this.getPhone) {
        // 授权登录过了
        this.hasLogin = false
        this.$pt.showTabBar({
          animation: false
        })
        this.$pt.setNavigationBarTitle({
          title: '店主中心'
        })
        let result = await this.getAuthority()
        result && this.getEntityByMemberId()
        for (let item of this.messageIdsArr) {
          this.messageSubscription(item)
        }
        this.unread['buyerUnread'] = this.$pt.getStorageSync('imUnreadBuyer') * 1 || this.getImUnreadBuyer * 1
        this.unread['sellerUnread'] = this.$pt.getStorageSync('imUnreadSeller') * 1 || this.getImUnreadSeller * 1
        let scanCode = this.$pt.getStorageSync('scanCode')
        if (scanCode) {
          // 如果是未授权用户扫码进来，授权完需要进入扫码后的界面
          switch (scanCode.path) {
            case 'pages/home/store-cancellation/order-cancellation/main':
              this.$pt.reLaunch({ url: '/pages/home/store-cancellation/order-cancellation/main?memberId=' + scanCode.memberId + '&orderId=' + scanCode.orderId })
              this.$pt.removeStorageSync('scanCode')
              break
            case 'pages/home/store-cancellation/orders-cancellation/main':
              this.$pt.reLaunch({ url: '/pages/home/store-cancellation/orders-cancellation/main?memberId=' + scanCode.memberId })
              this.$pt.removeStorageSync('scanCode')
              break
            default:
              break
          }
        }
        this.getMemberInfo()
        this.statOrder()
        this.getSysAppMarketByMemberId()
        this.getEnterpriseByMemberId()
        this.statMemberCommission()
        this.checkPayMethod(this.getCustomerId)
        this.enterpriseId = this.getEnterpriseId
        this.unread['sellerUnread'] = Number(this.$pt.getStorageSync('imUnreadSeller')) || Number(this.getImUnreadSeller)
        this.unread['buyerUnread'] = this.$pt.getStorageSync('imUnreadBuyer') * 1 || this.getImUnreadBuyer * 1
      } else {
        this.hasLogin = true
        this.$pt.hideTabBar({
          animation: false
        })
      }
    },
    checkPayMethod(customerId) {
      checkPayMethod({
        memberId: customerId
      }).then((response) => {
        if (response.data) {
          setPayMethod(response.data)
        } else {
          setPayMethod(1)
        }
      }).catch(() => {
      })
    },
    goSearchPage() {
      this.$pt.navigateTo({url: `/pages/order/order-search/main?searchvalue=${this.searchvalue}`})
    },
    getAppEls() {
      getAppInfo().then((response) => {
        if (response.isError) return
        let appInfo = response.data
        if (response.data.enterpriseId) {
          setEnterpriseId(response.data.enterpriseId)
        }
        this.groupBuyAuthority = appInfo.groupBuyAuthority
        this.getAppInfo = appColor(appInfo)
      }).catch(() => {
      })
      // return new Promise((resolve, reject) => {
      //   getAppInfo().then((response) => {
      //     if (response.isError) return
      //     let appInfo = response.data
      //     let versionNo = String(process.env.VERSION).split('')
      //     this.groupBuyAuthority = appInfo.groupBuyAuthority
      //     appInfo.appVersion = versionNo.join('.')
      //     setAppInfo(appInfo)
      //     this.getAppInfo = appInfo
      //     resolve(true)
      //   }).catch(() => {
      //   })
      // })
    },
    updateAuth() {
      this.initHome()
    },
    authority() {
      let memberInfo = this.memberInfo
      let appInfo = this.getAppInfo
      if (memberInfo.commanderStatus === 1) {
        // 符合其中一个条件就是门店身份
        if (memberInfo.memberStore.isHomeDelivery === 1 || memberInfo.memberStore.isStoreExtraction === 1) {
          // 判断是否有门店到家增值功能 1：有  0：无
          if (this.getAppInfo.storeHomeAuthority === 1) {
            // 判断门店是否为启用状态 1：启用 0：禁用
            if (memberInfo.storeState === 1) {
              // 判断门店是否有社区团购业务 1：有 0：没有
              if (memberInfo.memberStore.isCommunityGroupExtraction === 1) {
                // 设置社区团购业务缓存
                setCommunityGroup(1)
              } else {
                // 设置社区团购业务缓存
                setCommunityGroup(0)
              }
              // 有权限了 显示首页内容
              this.hasLogin = false
              this.$pt.showTabBar({
                animation: false
              })
            } else {
              this.$utils.showToast({
                title: '门店已被禁用，无法登陆',
                duration: 3000
              })
              setTimeout(() => {
                this.$pt.clearStorageSync()
                setAppInfo(appInfo)
                this.hasLogin = true
                this.$pt.hideTabBar({
                  animation: false
                })
              }, 3000)
            }
          } else {
            console.log('2没有门店到家增值功能，提示系统到期')
            // 没有门店到家增值功能，提示系统到期
            this.$utils.showToast({
              title: '系统已过期',
              duration: 3000
            })
            setTimeout(() => {
              this.$pt.clearStorageSync()
              setAppInfo(appInfo)
              this.hasLogin = true
              this.$pt.hideTabBar({
                animation: false
              })
            }, 3000)
          }
        } else {
          // 否则就是社群团长身份
          // 判断是否有社区团购增值功能 1：有 0：无
          if (this.getAppInfo.groupBuyAuthority === 1) {
            // 社区团长是否为启用状态 1: 启用 0：禁用
            if (memberInfo.commanderEnable === 1) {
              // 有权限了 显示首页内容
              this.hasLogin = false
              this.$pt.showTabBar({
                animation: false
              })
            } else {
              this.$utils.showToast({
                title: '团长已被禁用，无法登陆',
                duration: 3000
              })
              setTimeout(() => {
                this.$pt.clearStorageSync()
                setAppInfo(appInfo)
                this.hasLogin = true
                this.$pt.hideTabBar({
                  animation: false
                })
              }, 3000)
            }
          } else {
            console.log('2没有社区团购增值功能，提示系统到期')
            // 没有社区团购增值功能，提示系统到期
            this.$utils.showToast({
              title: '系统已过期',
              duration: 3000
            })
            setTimeout(() => {
              this.$pt.clearStorageSync()
              setAppInfo(appInfo)
              this.hasLogin = true
              this.$pt.hideTabBar({
                animation: false
              })
            }, 3000)
          }
        }
      } else {
        // 没有团长身份，判断是否有社群分销店主身份
        if (this.getVeekrayStatus === 1) {
        } else {
          // 判断是否有社区团购增值功能 1：有 0：无
          if (this.getAppInfo.groupBuyAuthority === 1) {
            // 判断是否申请过团长 true: 有 false：无
          } else {
            // 没有社区团购增值功能
            // 判断是否开启云店申请的Banner图入口 1：开启 0：禁用
            if (this.$pt.getStorageSync('unshoper')) {
              this.hasLogin = true
              this.$pt.hideTabBar({
                animation: false
              })
              return
            }
            if (this.getAppInfo.shopBannerShow === 1) {
              this.$pt.navigateTo({ url: '/pages/home/apply-shopowner/main' })
            } else {
              this.$utils.showToast({
                title: '暂无权限',
                duration: 3000
              })
              setTimeout(() => {
                this.$pt.clearStorageSync()
                setAppInfo(appInfo)
                this.hasLogin = true
                this.$pt.hideTabBar({
                  animation: false
                })
              }, 3000)
            }
          }
        }
      }
    },
    statOrder() {
      // 首页订单统计
      statOrder({memberId: this.getCustomerId}).then(response => {
        // console.log(response)
        if (response.isError) return
        this.statOrderTotal = response.data
      }).catch(() => {
      })
    },
    messageSubscription(messageItem) {
      messageItem['ids'] = []
      let dataStr = messageItem.dataArr.toString()
      listEnterpriseMessageConfig({
        memberId: this.getCustomerId,
        ascriptionTypes: dataStr
      })
        .then((response) => {
          if (response.isError) return
          response.data.forEach((item) => {
            if (item.miniMadeId) {
              messageItem['ids'].push(item.miniMadeId)
            }
          })
        })
        .catch(() => { })
    },
    // 运营总后台 增值功能权限获取
    getAuthority() {
      return new Promise((resolve, reject) => {
        getAuthority({enterpriseId: this.getEnterpriseId}).then(res => {
          this.shopCustomerServiceAuthority = res.data.shopCustomerServiceAuthority
          this.enterpriseCustomerServiceAuthority = res.data.enterpriseCustomerServiceAuthority
          this.shopSelectionAuthority = res.data.shopSelectionAuthority
          resolve(true)
        }).catch(err => {
          console.log(err)
        })
      })
    },
    getMemberInfo() {
      return new Promise((resolve, reject) => {
        getMemberInfo(this.getCustomerId).then((response) => {
          if (response.isError) return
          this.memberInfo = response.data
          this.memberStore = response.data.memberStore || {}
          this.$pt.setStorageSync('memberStore', this.memberStore)
          resolve(true)
          response.data.veekrayStatus && setVeekrayStatus(response.data.veekrayStatus)
          response.data.commanderStatus && setCommanderStatus(response.data.commanderStatus)
          // this.anchorAuth = response.data.anchorAuth // 获取该用户是否是主播
          if (response.data.commanderStatus === 1) {
            // 有门店身份或者团长身份，显示门店照片、门店名称、门店手机号
            this.storeLogo = this.memberInfo.memberStore.storeImage
            this.storeName = this.memberInfo.memberStore.storeName
            this.storePhone = this.getPhone
          } else {
            this.storeLogo = this.memberInfo.avatar
            this.storeName = this.memberInfo.nickname
            this.storePhone = this.memberInfo.phone
          }
          this.memberInfo.nickname = this.$utils.getStrByLength(
            this.memberInfo.nickname,
            13
          )
          // veekrayStatus 萤火微客注册状态 -1:未注册 0:免费名片 1:付费名片
          setNickName(response.data.nickname)
          if (response.data.enterpriseId) {
            setEnterpriseId(response.data.enterpriseId)
            this.enterpriseId = response.data.enterpriseId
          }
          if (response.data.veekrayStatus !== undefined) setVeekrayStatus(response.data.veekrayStatus)
          if (this.memberInfo.memberShareFlag === 1) {
            this.shareType = true
          } else {
            this.shareType = false
          }
        })
      })
    },
    getSysAppMarketByMemberId() {
      // 获取应用市场权限 (是否开通功能)
      let params = {
        memberId: this.getCustomerId,
        userType: 1, // 卖家状态
        appCode: 'pickUpFlag'
      }
      getSysAppMarketByMemberId(params).then((response) => {
        if (response.isError) return
        this.pickUpFlag = response.data
      })
    },
    serviceTo(type) {
      this.messageEls('service', '', 0)
    },
    messageSuccessTo(val, type) {
      let that = this
      switch (val) {
        case 'customer':
          // 自营订单
          that.$pt.navigateTo({
            url: '/pages/home/order/main?type=' + type
          })
          break
        case 'sell':
          // 分销订单
          that.$pt.navigateTo({
            url: '/pages/home/distribution/order/main?type=' + type
          })
          break
        case 'service':
          // 小B客服
          if (that.statusIs) {
            that.$pt.navigateTo({url: '/pages/home/message/list/main'})
          } else {
            that.buyerToService()
          }
          break
        case 'all':
          // 自营订单全部、分销订单全部
          if (that.activeIndex === 0 && that.entityData.selfGoodsAuthority === 1) {
            that.$pt.navigateTo({ url: '/pages/home/order/main' })
          } else {
            that.$pt.navigateTo({ url: '/pages/home/distribution/order/main' })
          }
          break
        case 'myCoupon':
          // 分销订单
          that.$pt.navigateTo({ url: '/pages/home/my-coupon/main' })
          break
      }
    },
    // 买家点击消息按钮(在自己店铺时显示 不能与自己聊天)
    buyerToService() {
      let cId = this.$pt.getStorageSync('customerId')
      let mId = this.$pt.getStorageSync('memberId')
      if (cId === mId) {
        this.$utils.showToast({
          title: '不能与自己聊天'
        })
      } else {
        this.$pt.navigateTo({url: '/pages/home/message/detail/main?memberId=' + this.getMemberId})
      }
    },
    messageEls(val, type, index) {
      let that = this
      let rejectArr = []
      if (!that.messageIdsArr[index]['ids'].length) {
        this.messageSuccessTo(val, type)
        return
      }
      this.$pt.requestSubscribeMessage({
        tmplIds: that.messageIdsArr[index].ids,
        success: function(res) {
          // 成功
          Object.keys(res).forEach((key) => {
            if (res[key] === 'reject') {
              rejectArr.push(key)
            }
          })
          if (rejectArr.length) {
            that.messageIdsArr[index].ids = rejectArr
            that.$utils.showToast({ title: '请允许消息通知！' })
          } else {
            that.messageSuccessTo(val, type)
          }
        },
        fail(err) {
          // 失败
          console.error(err)
        }
      })
    },
    statMemberCommission() {
      // 佣金统计 提现统计
      statMemberCommission({
        memberId: this.getCustomerId,
        month: this.$utils.formatTimeDate(new Date(), 'yyyy-MM-dd')
      }).then((response) => {
        if (response.isError) return
        this.memberStat.orderCommission = this.$utils.trsCount(response.data.orderCommission)
        this.memberStat.orderNum = this.$utils.trsCount(response.data.orderNum)
        this.memberStat.dailyAccess = this.$utils.trsCount(response.data.dailyAccess)
      }).catch(() => {
      })
    },
    getEnterpriseByMemberId() {
      if (!this.getMemberId) return
      getEnterpriseByMemberId({
        memberId: this.getMemberId
      }).then((response) => {
        if (response.isError) return
        this.enterpriseCopy = response.data
        this.showWatermarkAuthority = 'watermarkAuthority' in this.enterpriseCopy
      }).catch(() => {
      })
    },
    getScanning() {
      this.count++
      console.log('调用接口次数', this.count)
      //  未写完 需要学习
      this.$pt.scanCode({
        success: (res) => {
          console.log(res)
          let path = res.path
          if (!path) {
            this.$utils.showToast({
              title: '扫码异常，请扫码正确核销码!'
            })
            return
          }
          let pathAry = path.split('scene=')
          let index = pathAry[1].indexOf('&')
          if (index === -1) {
            this.parseShortCode(pathAry[1])
          } else {
            this.parseShortCode(pathAry[1].slice(0, index))
          }
        }
        // fail: (res) => {
        //   this.$utils.showToast({
        //     title: '扫码出错，请重新!',
        //     duration: 1500
        //   })
        // }
      })
    },
    parseShortCode(value) {
      let params = {}
      parseShortCode(value).then((response) => {
        if (response.isError) {
          this.resData = params
          if (this.getCustomerId) {
            this.$utils.setMyId(params.memberId)
            this.$root.$mp.appOptions.query = {}
            this.$pt.reLaunch({ url: '/pages/home/main' })
          } else {
            this.wxLogin(this.paramsData)
          }
          return
        }
        params = response.data
        console.log('params', params)
        if (params.path === 'pages/home/store-cancellation/orders-cancellation/main') {
          if (this.getCustomerId) {
            this.$pt.navigateTo({ url: '/pages/home/store-cancellation/orders-cancellation/main?memberId=' + params.memberId })
          } else {
            this.wxLogin(this.paramsData)
          }
        } else if (params.path === 'pages/home/store-cancellation/order-cancellation/main') {
          if (this.getCustomerId) {
            this.$pt.navigateTo({ url: '/pages/home/store-cancellation/order-cancellation/main?memberId=' + params.memberId + '&orderId=' + params.orderId })
          } else {
            this.wxLogin(this.paramsData)
          }
        } else {
          this.$utils.showToast({
            title: '扫码异常，请扫码正确核销码!',
            duration: 1500
          })
        }
      }).catch({})
    },
    goOrderList(type) {
      // 去订单列表页
      // type 1：门店自提（到家自提 待提货） 2：待提货（全部订单类型 待提货） 3：待配送（社区团购待配送） 4：全部订单
      this.$pt.setStorageSync('orderType', type)
      this.$pt.switchTab({ url: '/pages/order/main' })
    },
    switchAuth() {
      // 切换账号
      let loginType = this.$pt.getStorageSync('loginType')
      if (loginType === 1) {
        // 此时是社群/团长身份登录，去门店登录
        this.$pt.clearStorageSync()
        this.$pt.reLaunch({ url: '/pages/home/account-login/main' })
      } else if (loginType === 2) {
        // 此时是门店登录，去微信授权社群/团长身份登录
        this.$pt.clearStorageSync()
        setPhone('')
        setCustomerId('')
        setMemberId('')
        this.$pt.reLaunch({ url: '/pages/home/main' })
      } else {
        this.$pt.reLaunch({ url: '/pages/home/main' })
      }
    },
    getEntityByMemberId() {
      // 用来判断申请店播展示
      getEntityByMemberId({
        memberId: this.getCustomerId || ''
      }).then((response) => {
        // console.log(response)
        if (response.isError) return
        this.entityData = response.data
        // this.entityData.selfGoodsAuthority = 0
        if (response.data.taskPosterAuth) {
          this.taskPosterAuth = this.entityData.taskPosterAuth
        }
        // console.log('权限', this.shopSelectionAuthority)
        if (this.shopSelectionAuthority && this.entityData.liveAuthority && this.entityData.liveShowType) {
          this.barObj = {
            leftList: [{
              src: this.fileSpace + '/images/commodity-library-1.png',
              type: 1,
              className: 'height-125',
              titleFont: 'font-14',
              titleLeft: 'left: 15px;',
              lineOne: '商品库',
              lineTwo: '海量商品任你挑',
              linkTo: '/pages/home/commodity-library/main'
            }],
            rightList: [{
              src: this.fileSpace + '/images/video-shop-1.png',
              type: 2,
              className: 'height-62',
              titleFont: 'font-14',
              titleLeft: 'left: 15px;',
              lineOne: '申请店播',
              lineTwo: '你要的直播购物',
              linkTo: '/pages/home/live-apply/main'
            }, {
              src: this.fileSpace + '/images/pk-1.png',
              type: 3,
              className: 'height-62',
              titleFont: 'font-14',
              titleLeft: 'left: 15px;',
              lineOne: '直播分发PK榜',
              lineTwo: '查看您店铺的',
              lineThree: '直播间观众排名',
              linkTo: '/pages/home/live-pk/main'
            }]
          }
        } else if (this.shopSelectionAuthority && this.entityData.liveAuthority && !this.entityData.liveShowType) {
          this.barObj = {
            leftList: [{
              src: this.fileSpace + '/images/commodity-library-2.png',
              type: 1,
              className: 'height-62',
              titleFont: 'font-14',
              titleLeft: 'left: 15px;',
              lineOne: '商品库',
              lineTwo: '海量商品任你挑',
              linkTo: '/pages/home/commodity-library/main'
            }],
            rightList: [{
              src: this.fileSpace + '/images/video-shop-1.png',
              type: 2,
              className: 'height-62',
              titleFont: 'font-14',
              titleLeft: 'left: 15px;',
              lineOne: '申请店播',
              lineTwo: '你要的直播购物',
              linkTo: '/pages/home/live-apply/main'
            }]
          }
        } else if (this.shopSelectionAuthority && !this.entityData.liveAuthority && this.entityData.liveShowType) {
          this.barObj = {
            leftList: [{
              src: this.fileSpace + '/images/commodity-library-1.png',
              type: 1,
              className: 'height-62',
              titleFont: 'font-14',
              titleLeft: 'left: 15px;',
              lineOne: '商品库',
              lineTwo: '海量商品任你挑',
              linkTo: '/pages/home/commodity-library/main'
            }],
            rightList: [{
              src: this.fileSpace + '/images/pk-1.png',
              type: 3,
              className: 'height-62',
              titleFont: 'font-14',
              titleLeft: 'left: 15px;',
              lineOne: '直播分发PK榜',
              lineTwo: '查看您店铺的',
              lineThree: '直播间观众排名',
              linkTo: '/pages/home/live-pk/main'
            }]
          }
        } else if (this.shopSelectionAuthority && !this.entityData.liveAuthority && !this.entityData.liveShowType) {
          this.barObj = {
            leftList: [{
              src: this.fileSpace + '/images/commodity-library-3.png',
              type: 1,
              className: 'height-42',
              titleFont: 'font-12',
              titleLeft: 'left: 74px;',
              lineOne: '商品库',
              lineTwo: '海量商品任你挑',
              linkTo: '/pages/home/commodity-library/main'
            }],
            rightList: []
          }
        } else if (!this.shopSelectionAuthority && this.entityData.liveAuthority && this.entityData.liveShowType) {
          this.barObj = {
            leftList: [{
              src: this.fileSpace + '/images/video-shop-1.png',
              type: 2,
              className: 'height-62',
              titleFont: 'font-14',
              titleLeft: 'left: 15px;',
              lineOne: '申请店播',
              lineTwo: '你要的直播购物',
              linkTo: '/pages/home/live-apply/main'
            }],
            rightList: [{
              src: this.fileSpace + '/images/pk-1.png',
              type: 3,
              className: 'height-62',
              titleFont: 'font-14',
              titleLeft: 'left: 15px;',
              lineOne: '直播分发PK榜',
              lineTwo: '查看您店铺的',
              lineThree: '直播间观众排名',
              linkTo: '/pages/home/live-pk/main'
            }]
          }
        } else if (!this.shopSelectionAuthority && this.entityData.liveAuthority && !this.entityData.liveShowType) {
          this.barObj = {
            leftList: [{
              src: this.fileSpace + '/images/video-shop-2.png',
              type: 2,
              className: 'height-42',
              titleFont: 'font-12',
              titleLeft: 'left: 74px;',
              lineOne: '申请店播',
              lineTwo: '你要的直播购物',
              linkTo: '/pages/home/live-apply/main'
            }],
            rightList: []
          }
        } else if (!this.shopSelectionAuthority && !this.entityData.liveAuthority && this.entityData.liveShowType) {
          this.barObj = {
            leftList: [{
              src: this.fileSpace + '/images/pk-2.png',
              type: 3,
              className: 'height-42',
              titleFont: 'font-12',
              titleLeft: 'left: 82px;',
              lineOne: '直播分发PK榜',
              lineTwo: '查看您店铺的直播间观众排名',
              linkTo: '/pages/home/live-pk/main'
            }],
            rightList: []
          }
        }
        if (!this.entityData.selfGoodsAuthority) {
          this.tab = [
            { name: this.getAppInfo.projectOrderAlias || '分销订单', orderType: 30, count: null }
          ]
        } else {
          this.tab = [
            { name: '自营订单', orderType: 10, count: null },
            { name: this.getAppInfo.projectOrderAlias || '分销订单', orderType: 30, count: null }
          ]
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
.store{
  .store-center{
    position: relative;
    overflow-x: hidden;
    &::before{
      content: '';
      position: absolute;
      left: -30%;
      width: 160%;
      height: 448rpx;
      background: linear-gradient(to bottom, #FF243D, #FF3C52);
      z-index: -1;
      border-radius: 0 0 50% 50%;
    }
    .store-nav{
      position: fixed;
      left: 0;
      top: 0;
      width: 100%;
      background-color: #FF243D;
      z-index: 99;
      .switch-auth{
        position: absolute;
        left: 12px;
        top: 0;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #fff;
      }
      .store-title{
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 18px;
        color: #FFF;
        font-weight: bold;
      }
    }
    .aling-l{
      display: flex;
      align-items: center;
      justify-content: flex-start;
    }
    .store-info{
      color: #FFF;
      font-size: 15px;
      line-height: 1.3;
      .store-logo{
        width: 49px;
        height: 49px;
        border-radius: 10px;
        background-color: #fff;
      }
      .switch-info{
        width: 92px;
        height: 30px;
        border-radius: 15px 0 0 15px;
        background-color: rgba(255, 255, 255, .2);
        font-size: 12px;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-right: -12px;
      }
    }
    .increment-box{
      height: 78px;
      border-radius: 10px;
      padding: 0 5px;
      background-color: #FFF;
      margin-top: 10px;
      .width-max{
        width: 100%;
      }
      .text-layer{
        position: absolute;
        top: 0;
        line-height: 1.4;
        height: 100%;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: flex-start;
      }
      .font-81{
        color: #818181;
      }
    }
    .pancel-bar {
      background: #fff;
      border-radius: 12px;
      box-shadow: 0 4px 9px rgba(133, 133, 133, 0.2);
      position: relative;
      z-index: 5;
      &.none-radius {
        .pancel-title {
          padding-top: 13px;
          padding-left: 35rpx;
          font-weight: 700;
          font-size: 30rpx;
        }
      }
      .shop-tools {
        flex-wrap: wrap;
        .self-flex-item {
          width: 25%;
        }
        .new-item {
          position: relative;
          .new-tag {
            position: absolute;
            width: 44rpx;
            height: 24rpx;
            font-size: 16rpx;
            background: #f00;
            color: #fff;
            border-radius: 6px 6px 6px 0;
            top: -10rpx;
            right: 30rpx;
          }
        }
      }
      .news-tag-style1{
        position: absolute;
        font-size: 18rpx;
        background: #f00;
        color: #fff;
        border-radius: 5px;
        top: -7px;
        right: 44rpx;
        padding: 0px 4rpx;
      }
      .news-tag-style2 {
        position: absolute;
        font-size: 18rpx;
        background: #f00;
        color: #fff;
        border-radius: 50%;
        top: -7rpx;
        right: 55rpx;
        width: 30rpx;
        height: 30rpx;
        text-align: center;
      }
      .tabs-box {
        padding-right: 43%;
        padding-left: 3%;
        border-bottom: #f1f1f1 1px solid;
        &.tabs-box-0 {
          padding-right: 70%;
        }
        .van-infos {
          position: absolute;
          top: 3px;
          z-index: 20;
          &.we-infos {
            left: 24%;
          }
          &.sell-infos {
            left: 54%;
            &.sell-tag-0 {
              left: 25%;
            }
          }
        }
        /deep/ .van-tab__title {
          position: relative;
          z-index: 2;
        }
      }
      ul {
        &.sell-o-list {
          li {
            &:nth-child(2),
            &:nth-child(3),
            &:nth-child(4) {
              .van-infos {
                left: 57% !important;
              }
            }
            .van-infos {
              position: absolute;
              left: 62%;
              top: -5px;
            }
          }
        }
        &.buyer-o-list {
          li {
            &:nth-child(1) {
              .van-infos {
                left: 58% !important;
              }
            }
            &:nth-child(4) {
              .van-infos {
                left: 56% !important;
              }
            }
            .van-infos {
              position: absolute;
              left: 60%;
              top: -5px;
            }
          }
        }
        li {
          text-align: center;
          img {
            display: inline-block;
            margin-bottom: 18rpx;
          }
          label {
            display: block;
            font-size: 12px;
            margin-top: -3px;
          }
        }
      }
    }
    .contactBtn {
      background-color: transparent !important;
      position: absolute;
      width: 100%;
      height: 100%;
      left: 0;
      top: 0;
      z-index: 999;
      border-color: transparent !important;
      border: none !important;
    }
    .cancellation-tool{
      .tool-line{
        position: relative;
        &::after{
          content: '';
          position: absolute;
          right: 0;
          bottom: -31px;
          width: 1px;
          height: 124px;
          background-color: #F3F3F3;
          transform: scale(.5);
        }
      }
      .tool-icon{
        width: 44px;
        height: 44px;
        border-radius: 13px;
      }
    }
    .order-tip{
      padding-left: 18px;
      padding-right: 18px;
      padding-bottom: 14px;
      margin-top: 35px;
      display: flex;
      justify-content: space-around;
      align-items: center;
    }
  }
  .copy-right-logo {
    padding-bottom: 25px;
    img {
      margin: 12px auto 3px auto;
    }
    p {
      color: #cccccc;
    }
  }
  .cancellation-dot{
    position: absolute;
    left: 36px;
    top: -8px;
    height: 16px;
    line-height: 16px;
    font-size: 10px;
    border-radius: 16px;
    background-color: #FF243D;
    border: 1px solid #fff;
    min-width: 12px;
    text-align: center;
    color: #fff;
    font-weight: 300;
    white-space: nowrap;
    padding: 0 2px;
  }
  .search-box {
    margin-top: 20px;
    position: relative;
    input {
      padding-top: 2px;
      padding-bottom: 2px;
      padding-right: 40px;
      background: #fff;
      border-radius: 20px;
    }
    &>span {
      position: absolute;
      right: 0;
      top: 0;
      z-index: 10;
      height: 100%;
      width: 40px;
      display: flex;
      align-items: center;
      justify-content: center;
    }
  }
}
</style>
